<?php

class BackendController extends Zend_Controller_Action {

	const HOMEPAGE_URL = 'http://vw-group.pl/';

	private $params; 
	
  public function init() {
  	if (!$this->getRequest()->isXmlHttpRequest()) {
      $this->_helper->redirector->gotoUrlAndExit(self::HOMEPAGE_URL);
      return;
  	}
  	$post = $this->getRequest()->getParams();
  	$this->params = (array_key_exists('params', $post)) ? new Core_Params($post['params']) : null;
  	$this->jsonData();
  	
  	if ($this->params->app === null)
  		throw new Exception("Object App can't be empty!");
  	
  	Core_Auth::getInstance();
  	Core_Core::getInstance()->setApp(new App_Methods_Data_App($this->params->app));
  }
  
  public function jsonData() {
  	$this->_helper->layout->disableLayout();
  	$action = $this->getRequest()->getActionName();
  	$this->_helper->viewRenderer->setNoRender(true);
  	$this->_helper->contextSwitch()
  	->addActionContext($action, 'json')
  	->setAutoJsonSerialization(true)
  	->initContext('json');
  	$this->getRequest()->setParam('format', 'json');
  }

  public function getMenuDataAction() {
  	$request = new App_Methods_Request_GetMenuData($this->params);
		$this->view->response = $request->process();
  }
  
  public function saveOrderAction() {
  	$request = new App_Methods_Request_SaveOrder($this->params);
  	$this->view->response = $request->process();
  }
  
  public function hideAppAction() {
  	$request = new App_Methods_Request_HideApp($this->params);
  	$this->view->response = $request->process();
  }
  
  public function getUserPulpitAppAction() {
  	$request = new App_Methods_Request_GetUserPulpitApp($this->params);
  	$this->view->response = $request->process();
  }
  
  public function getUserPulpitListAction() {
  	$request = new App_Methods_Request_GetUserPulpitList($this->params);
  	$this->view->response = $request->process();
  }
  
  public function saveUserPulpitAction() {
  	$request = new App_Methods_Request_SaveUserPulpit($this->params);
  	$this->view->response = $request->process();
  }
  
  public function saveUserPulpitVisibilitiesAction() {
  	$request = new App_Methods_Request_SaveUserPulpitVisibilities($this->params);
  	$this->view->response = $request->process();
  }
  
  public function getUserDataAction() {
  	$request = new App_Methods_Request_GetUserData($this->params);
  	$this->view->response = $request->process();
  }
  
  public function getUserListAction() {
  	$request = new App_Methods_Request_GetUserList($this->params);
  	$this->view->response = $request->process();
  }
  
  public function getUserGroupListAction() {
  	$request = new App_Methods_Request_GetUserGroupList($this->params);
  	$this->view->response = $request->process();
  }
  
  public function setActiveAction() {
  	$request = new App_Methods_Request_SetActive($this->params);
  	$this->view->response = $request->process();
  }
  
  public function setUserGroupAction() {
  	$request = new App_Methods_Request_SetUserGroup($this->params);
  	$this->view->response = $request->process();
  }
  
  public function getUserGroupApplicationsAction() {
  	$request = new App_Methods_Request_GetUserGroupApplications($this->params);
  	$this->view->response = $request->process();
  }
  
  public function setGroupApplicationAction() {
  	$request = new App_Methods_Request_SetGroupApplication($this->params);
  	$this->view->response = $request->process();
  }
  
  public function addUserGroupAction() {
  	$request = new App_Methods_Request_AddUserGroup($this->params);
  	$this->view->response = $request->process();
  }
  
  public function removeUserGroupAction() {
  	$request = new App_Methods_Request_RemoveUserGroup($this->params);
  	$this->view->response = $request->process();
  }
  
}